﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreEx.Common.Proxy;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;

namespace CoreEx.Common.Implementation.Proxy
{
    [Factory(typeof(IInterceptor<>))]
    public class InterceptorFactory : IFactory
    {
        public object CreateInstance(IFactoryRequest request)
        {
            Type mapperType = typeof(IInterceptor<>);
            Type genericInterceptorType = mapperType.MakeGenericType(request.ServiceType.GetGenericArguments());
            object instance = Activator.CreateInstance(genericInterceptorType);
            ((IInitialize)instance).Initialize(request.Container);
            return instance; 
        }
    }
}
